package com.itheima.mytest;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class Test02 {
    public static void main(String[] args) throws IOException {
        //1.进行数据的读
        FileReader fr = new FileReader("myio\\a.txt");
        StringBuilder sb = new StringBuilder();
        //2.将数据放入sb集合
        int ch;
        while ((ch = fr.read()) != -1) {
            sb.append((char) ch);
        }
        fr.close();
        //3.进行排序
       // Integer.parseInt(Arrays.toString(sb.toString().split("-")))
        Integer[] arr = Arrays.stream(sb.toString()
                        .split("-"))
                .map(Integer::parseInt)
                .sorted()
                .toArray(Integer[]::new);

        //4.进行数据的写出
        FileWriter fw = new FileWriter("myio\\a.txt");
        String s = Arrays.toString(arr).replace("-", ",");
        String result = s.substring(1, s.length() - 1);
        System.out.println(result);
        fw.close();
    }
}
